{include 'admin/layout/header_list'}
<link rel="stylesheet" href="__ADMIN_STATIC__/css/plugin.css?random={extendSetting('random')}">
<link rel="stylesheet" href="__ADMIN_STATIC__/css/pop_window.css?random={extendSetting('random')}">
<link rel="stylesheet" href="__ADMIN_STATIC__/css/iconfont.css?random={extendSetting('random')}">
<div class="ltcms_container">
    <div class="container_title">
        <form action="{LTCMS_ROUTE_PREFIX}/appStore" method="get" class="ltcms_search">
            <input name="name" type="text" placeholder="请输入软件名称" {if isset($request['name'])} value="{$request['name']}"
                {/if}>
            <button type="submit" class="btn3">搜索</button>
        </form>
    </div>
    <section class="ltcms_content">
        <div class="ltcms_list">
            <table class="list_table">
                <colgroup>
                    <col width="40px">
                    <col width="200px">
                    <col width="200px">
                    <col width="140px">
                    <col width="140px">
                    <col>
                </colgroup>
                <tr>
                    <td class="th"><input id="selectAll" type="checkbox"></td>
                    <td class="th">软件名称</td>
                    <td class="th">软件介绍</td>
                    <td class="th">开发者</td>
                    <td class="th">软件价格</td>
                    <td class="th">状态</td>
                    <td class="th">操作</td>
                </tr>
                {if $listData}
                {foreach $listData["data"] $key $val}
                <tr>
                    <td><input class="checkbox" name="check_id" type="checkbox" value="{$val['id']}"></td>
                    <td>{$val['pluginData']["name"]}</td>
                    <td>{$val['pluginData']["desc"]}</td>
                    <td>{$val['pluginData']["nickname"]}</td>
                    <td>{$val['sellPrice']}</td>
                    <td>{array_path(["","启用","停用"],array_path($pluginsList[$val['pluginData']['id']],'status',0))}</td>
                    <td>
                        {if isset($val['pluginData']["isValid"])}
                        {if $val['pluginData']["isValid"] ||env()->get("APP_debug", "")}
                        <div class="btn4">
                            {if !isset($pluginsList[$val['pluginData']["id"]])}
                            <a class="installBtn{$val['id']}" href="javascript:void(0);"
                                onclick="openInstall(this,'{LTCMS_ROUTE_PREFIX}/run?pluginId={$val['pluginData']['id']}&id={$val['id']}')"
                                title="安装">
                                <i class="btn4-img iconfont icon-ruanjianshengji"></i>
                            </a>
                            {else}
                                {if array_path($pluginsList[$val['pluginData']['id']],'setUpView.enable',0)==1}
                                <a class="" href="javascript:void(0);" title="设置"
                                    onclick="openPluginsSetting({$val['pluginData']['id']},{array_path($pluginsList[$val['pluginData']['id']],'setUpView.width',50)},{array_path($pluginsList[$val['pluginData']['id']],'setUpView.height',50)})">
                                    <i class="btn4-img iconfont icon-setting"></i>
                                </a>
                                {/if}
                                <a href="javascript:void(0);" title="卸载"
                                    onclick="uninstall({$val['pluginData']['id']},'{$val['pluginData']['name']}')">
                                    <i class="btn4-img iconfont icon-delete"></i>
                                </a>
                                <a class="installBtn{$val['id']}" href="javascript:void(0);"
                                   onclick="openInstall(this,'{LTCMS_ROUTE_PREFIX}/run?pluginId={$val['pluginData']['id']}&id={$val['id']}')" title="升级">
                                    <i class="btn4-img iconfont icon-ruanjianshengji"></i>
                                </a>
                            {/if}
                        </div>
                        {else}
                        <div class="btn4">
                            <a href="javascript:void(0);" title="立即购买">
                                <i class="btn4-img iconfont icon-goumai"></i>
                            </a>
                        </div>
                        {/if}
                        {/if}
                    </td>
                </tr>
                {/foreach}
                {/if}
            </table>
        </div>
    </section>
    <div class="list-bottom">
        <div class="bottom-left">
            <a href="{LTCMS_ROUTE_PREFIX}/usedByCardName">
                <button class="btn2 trash">激活插件</button>
            </a>
            {if env()->get("APP_debug", "")==1}
            <!--开发者模式安装未上架测插件-->
            <button class="btn2 trash" onclick="pluginInstall()" >安装本地插件</button>
            {/if}
        </div>
        <div class="pages">
            {if $listData}
            {php echo app("P_page")->getPageBarV2($listData);}
            {/if}
        </div>
    </div>
</div>
<script>
    function openInstall(obj, url) {
        var step = $(obj).attr("step");
        if (step == "1") {
            url += "&step=1";
            pop("安装", url, '900px', '500px');
        } else if (step == "2") {
            url += "&step=2";
            $(obj).attr("step", "0");
            pop("安装", url, '700px', '400px', true);
        } else {
            pop("安装", url, '600px', '250px');
        }
    }

    function openPluginsSetting(pluginId, x = 660, y = 660) {
        let url = "{LTCMS_ROUTE_PREFIX}/setUpView?pluginId=" + pluginId
        pop("安装", url, x + 'px', y + 'px'); //这个可以带关闭按钮
    }

    //卸载插件
    function uninstall(id, name) {
        layer.confirm('您确定要卸载[' + name + ']吗？', {
            title: "操作提示",
            icon: 0,
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            //按钮【按钮一】的回调
            let msgIndex = layer.msg('正在处理', {
                icon: 16,
                shade: 0.05,
                time: 60000
            });
            $.post("{LTCMS_ROUTE_PREFIX}/uninstall", {
                    _method: "delete",
                    pluginId: id,
                },
                function (data, status) {
                    layer.close(msgIndex)
                    layer.msg(data.codeMsg, {
                        icon: data.code === 0 ? 1 : 2,
                        time: 1000
                    });
                    if (data.code === 0) {
                        location.reload(); //卸载完成刷新页面
                    }
                });
        });
    }

    function pluginInstall() {
        //输入插件路径
        let path = prompt("请输入插件路径", "");
        if(path){
            let url='/api/execScript/pluginInstall?pluginDir='+path;
            //打开新窗口访问改地址
            window.open(url);
        }
    }
</script>
<script src="__ADMIN_STATIC__/js/pop_window.js?random={extendSetting('random')}"></script>
<script src="__ADMIN_STATIC__/js/list.js?random={extendSetting('random')}"></script>
{include 'admin/layout/footer'}